﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MatrixController : MonoBehaviour
{
    //格子元素
    public GameObject box;

    //矩阵边长
    public int matrix_length;

    //格子间隔
    public float box_gap;

    private void Start()
    {
        GenerateMatrix();
    }

    //生成矩阵
    private void GenerateMatrix()
    {
        Vector3[] verticePoses = box.GetComponent<MeshFilter>().sharedMesh.vertices;
        float box_length = Vector3.Distance(verticePoses[0], verticePoses[1]);
        Debug.Log("获取到格子边长：" + box_length);
        if(matrix_length > 0)
            for(int index_x = -(matrix_length / 2);index_x <= matrix_length / 2; index_x++)
                for (int index_y = -(matrix_length / 2); index_y <= matrix_length / 2; index_y++)
                {
                    GameObject block = Instantiate(box);
                    block.transform.position = new Vector3(index_x, 0, index_y) * (box_length + box_gap);
                }
    }
}
